import _ from 'lodash';

export const useColumns = (columns) => {
  const deepColumn = _.cloneDeep(columns);
  const innerColumns = deepColumn.map((item) => {
    const customRender = item.customRender;

    if (item.customRender && typeof item.customRender === 'function') {
      item.customRender = (arg) => customRender(arg);
    }
    if (item.actions) {
      item.customRender = (arg) =>
        item.actions.map((t) => {
          const { label, onClick, ...rest } = t;
          return (
            <a-button onClick={() => onClick(arg)} {...rest}>
              {label}
            </a-button>
          );
        });
    }

    return item;
  });
  return innerColumns;
};
